package com.thread.thread05;
/**
 * synchronized的重入
 */
public class SyncDubbo2 {

	
	static class Main{
		public int t = 10;
		public synchronized void operationSup() throws InterruptedException {
			t--;
			System.out.println("Main is = " +t);
			Thread.sleep(2000);
		}
	}
	
	static class Sub extends Main {
		public synchronized void operationSub() throws InterruptedException {
			while (t > 0) {
				t--;
				System.out.println("Sub is =" +t);
				Thread.sleep(2000);
				super.operationSup();
			}	
		}
	}
	
	public static void main(String[] args) {
		Thread t = new Thread(new Runnable() {
			
			@Override
			public void run() {
				Sub sub = new Sub();
				try {
					sub.operationSub();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		t.start();
	}
}
